﻿
@{
    ViewBag.Title = "Edit";
}
<br />
<form class="form-horizontal" role="form">
    <div class="form-group">
        <label for="BusCode" class="col-sm-2 control-label">编码</label>
        <div class="col-sm-10">
            <input type="text" class="form-control" id="BusCode" v-model="form.BusCode" placeholder="请输入编码">
        </div>
    </div>
    <div class="form-group">
        <label for="BusName" class="col-sm-2 control-label">名称</label>
        <div class="col-sm-10">
            <input type="text" class="form-control" id="BusName" v-model="form.BusName" placeholder="请输入名称">
        </div>
    </div>
    <div class="form-group">
        <label for="url" class="col-sm-2 control-label">调用地址</label>
        <div class="col-sm-10">
            <input type="text" class="form-control" id="url" v-model="form.Url" placeholder="请输入调用地址">
        </div>
    </div>
    <div class="form-group">
        <label for="UserName" class="col-sm-2 control-label">申请人</label>
        <div class="col-sm-10">
            <input type="text" disabled="disabled" class="form-control" id="UserName" v-model="form.UserName" placeholder="请输入申请人">
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <div class="checkbox">
                <label>
                    <input v-model="form.IsActive" type="checkbox">是否启用
                </label>
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <button type="button" v-on:click="save()" class="btn btn-default">保 存</button>
        </div>
    </div>
</form>

@section script{
    <script>
        var vm = new Vue({
            el: "#app",
            data: {
                id: "@ViewBag.id",
                form: {
                    IsActive: 1,
                    UserName: 'niuhk'
                }
            },
            methods: {
                init: function () {
                    var ths = this;
                    if (!ths.id) {
                        return;
                    }
                    $.post("@Url.Action("Get", "Home")",
                        { id: ths.id },
                        function (res) {
                            ths.form = res;
                        });
                },
                save: function () {
                    var ths = this;
                    var data = $.extend(true, ths.form, { IsActive: ths.form.IsActive ? 1 : 0 });
                    $.post("@Url.Action("Save", "Home")",
                        data,
                        function (res) {
                            debugger
                            if (res.success) {
                                location.href = "/home/index";
                            } else {
                                alert("报错失败");
                            }
                        });
                }
            },
            created: function () {
                this.init();
            }
        });
    </script>
}